package com.softer.wxzj.controller;

import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.aop.annotation.LogRecord;
import com.softer.wxzj.common.aop.enums.LogOperationType;
import com.softer.wxzj.common.aop.enums.LogOperationUnit;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.common.util.ShiroUserUtil;
import com.softer.wxzj.entity.*;
import com.softer.wxzj.service.BaseOrganizationService;
import com.softer.wxzj.service.impl.BaseOrganizationServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *    
 *  @ClassName: BaseOrganizationController
 *  @Description: 企业基本信息
 *  @Author:  zcz 
 *  @CreateDate: 2019-05-10   
 */
@RestController
@RequestMapping("/baseOrganization")
@Slf4j
public class BaseOrganizationController {

    @Autowired
    BaseOrganizationService organizationService;
    @Autowired
    BaseOrganizationServiceImpl OrganizationServiceImpl;

    /**
     * 备案页面检查是否可操作   （已废弃接口）
     *
     * @param id
     * @return
     */
    @RequestMapping("/checkOperation")
    public CommonResult checkOperation(@RequestParam("id") String id) {
        return organizationService.getCountByIdAndCreater(id);
    }

    /**
     * 添加审核
     *
     * @param id      业务ID
     * @param opinion 审核意见
     * @param mark    审批通过 audit_pass
     *                审批否决 audit_veto
     *                审批退回 audit_back
     * @return 审核结果
     */
    @RequestMapping("/addAudit")
    public CommonResult audit(@RequestParam("id") String id, String opinion, @RequestParam("mark") String mark) {
        return organizationService.addAudit(id, opinion, mark);
    }

    /**
     * 新增提交审批
     *
     * @param id
     * @return
     */
    @RequestMapping("/submitAudit")
    public CommonResult submitAudit(@RequestParam("id") String id,String operNo) {
        return organizationService.submitAudit(id,operNo);
    }

    /**
     * 提交并保存审批
     *
     * @param baseOrganization
     * @return
     */
    @RequestMapping("/submitAuditAndAdd")
    public CommonResult submitAuditAndAdd(@RequestBody BaseOrganization baseOrganization) {
        return organizationService.submitAuditAndAdd(baseOrganization);
    }

    /**
     * 修改并保存审批
     *
     * @param baseOrganization
     * @return
     */
    @RequestMapping("/updateAndAdd")
    public CommonResult updateAndAdd(@RequestBody BaseOrganization baseOrganization) {
        return organizationService.updateAndAdd(baseOrganization);
    }

    /**
     * 变更审核
     *
     * @param id      变更Id
     * @param opinion 审核意见
     * @param mark    审批通过 audit_pass
     *                审批否决 audit_veto
     *                审批退回 audit_back
     * @return 审核结果
     */
    @RequestMapping("/modifyAudit")
    public CommonResult modifyAudit(@RequestParam("id") String id, String opinion, @RequestParam("mark") String mark) {
        return organizationService.modifyAudit(id, opinion, mark);
    }

    /**
     * 新增备案   审批通过
     *
     * @param id
     * @return
     */
    @RequestMapping("/auditPass")
    public CommonResult updateAudit(@RequestParam("id") String id) {
        return organizationService.auditPass(id);
    }

    /**
     * 获取待审核信息列表
     *
     * @param page
     * @param organization
     * @return
     */
    @RequestMapping("/getAuditList")
    @LogRecord(description = "获取企业信息列表", operationUnit = LogOperationUnit.BASE_ORGANIZATION, operationType = LogOperationType.SELECT)
    public PageInfo<BaseOrganization> getAuditList(Page page, BaseOrganization organization, @RequestParam("flowType") String flowType) {
        return organizationService.getAuditList(page, organization, flowType);
    }

    /**
     * 获取变更信息列表 flowState:1待审批   1,2,3,4查询所有
     *
     * @param page
     * @param organization
     * @return
     */
    @RequestMapping("/getModifyList")
    @LogRecord(description = "获取变更信息列表", operationUnit = LogOperationUnit.BASE_ORGANIZATION, operationType = LogOperationType.SELECT)
    public PageInfo<BaseOrganization> getModifyList(Page page, BaseOrganization organization) {
        return organizationService.getModifyList(page, organization);
    }

    /**
     * 外网获取变更信息列表
     *
     * @param page         分页信息
     * @param organization 查询信息
     * @return 企业变更列表
     */
    @RequestMapping("/getModifyListToExtraNet")
    @LogRecord(description = "外网获取变更信息列表", operationUnit = LogOperationUnit.BASE_ORGANIZATION, operationType = LogOperationType.SELECT)
    public PageInfo<BaseOrganization> getModifyListToExtraNet(Page page, BaseOrganization organization) {
        return organizationService.getModifyListToExtraNet(page, organization);
    }

    /**
     * 获取变更信息列表 flowState:1待审批   1,2,3,4查询所有
     *
     * @param page
     * @param organization
     * @return
     */
    @RequestMapping("/getModifyAuditList")
    @LogRecord(description = "获取变更信息待审批列表", operationUnit = LogOperationUnit.BASE_ORGANIZATION, operationType = LogOperationType.SELECT)
    public PageInfo<BaseOrganization> getModifyAuditList(Page page, BaseOrganization organization) {
        return organizationService.getModifyAuditList(page, organization);
    }

    /**
     * 主管端添加企业基本信息
     *
     * @param organization 企业信息参数
     * @return 结果
     */
    @RequestMapping("/add")
    @LogRecord(description = "主管端添加企业信息", operationUnit = LogOperationUnit.BASE_ORGANIZATION, operationType = LogOperationType.INSERT)
    public CommonResult add(@RequestBody BaseOrganization organization) {
        log.info("添加企业信息,操作人:{}", ShiroUserUtil.getUserName());
        return organizationService.insert(organization);
    }

    /**
     * 根据id删除企业基本信息
     *
     * @param id 企业id
     * @return 结果
     */
    @RequestMapping("/delete")
    @LogRecord(description = "企业信息删除", operationUnit = LogOperationUnit.BASE_ORGANIZATION, operationType = LogOperationType.DELETE)
    public CommonResult delete(String id) {
        return organizationService.delete(id);
    }

    /**
     * 根据id更新企业基本信息 整体变更
     *
     * @param organization 企业信息参数
     * @return
     */
    @RequestMapping("/update")
    @LogRecord(description = "企业信息修改", operationUnit = LogOperationUnit.BASE_ORGANIZATION, operationType = LogOperationType.UPDATE)
    public CommonResult update(@RequestBody BaseOrganization organization) {
        return organizationService.update(organization);
    }

    /**
     * 根据id更新企业基本信息  选择变更
     *
     * @param organization 企业信息参数
     * @return
     */
    @RequestMapping("/updateSelective")
    @LogRecord(description = "企业信息动态修改", operationUnit = LogOperationUnit.BASE_ORGANIZATION, operationType = LogOperationType.UPDATE)
    public CommonResult updateSelective(BaseOrganization organization) {
        return organizationService.updateSelective(organization);
    }

    @RequestMapping("/modify")
    @LogRecord(description = "企业信息变更", operationUnit = LogOperationUnit.BASE_ORGANIZATION, operationType = LogOperationType.UPDATE)
    public CommonResult modify(@RequestBody BaseOrganization baseOrganization) throws Exception {
        return organizationService.modify(baseOrganization);
    }

    /**
     * 获取企业信息列表
     *
     * @param page
     * @param organization
     * @return 企业信息列表
     */
    @RequestMapping("/getList")
    @LogRecord(description = "获取企业信息列表", operationUnit = LogOperationUnit.BASE_ORGANIZATION, operationType = LogOperationType.SELECT)
    public PageInfo<BaseOrganization> getList(Page page, BaseOrganization organization) {
        return organizationService.getList(page, organization);
    }

    /**
     * 获取备案信息列表
     *
     * @param page
     * @param organization
     * @return 企业信息列表
     */
    @RequestMapping("/getRecordList")
    @LogRecord(description = "获取备案信息列表", operationUnit = LogOperationUnit.BASE_ORGANIZATION, operationType = LogOperationType.SELECT)
    public PageInfo<BaseOrganization> getRecordList(Page page, BaseOrganization organization) {
        return organizationService.getRecordList(page, organization);
    }

    /**
     * 获取待提交信息列表
     *
     * @param page
     * @param organization
     * @return 企业信息列表
     */
    @RequestMapping("/getWaitSubmitList")
    @LogRecord(description = "获取待提交信息列表", operationUnit = LogOperationUnit.BASE_ORGANIZATION, operationType = LogOperationType.SELECT)
    public PageInfo<BaseOrganization> getWaitSubmitList(Page page, BaseOrganization organization) {
        return organizationService.getWaitSubmitList(page, organization);
    }

    /**
     * 根据id获取企业详情
     *
     * @param id      企业id
     * @param arcType 图档大类
     * @return 企业基本信息
     */
    @RequestMapping("/getInfo")
    @LogRecord(description = "根据id获取企业基本信息详情", operationUnit = LogOperationUnit.BASE_ORGANIZATION, operationType = LogOperationType.SELECT)
    public BaseOrganization getInfo(String id, String arcType) {
        return organizationService.getInfoById(id, arcType);
    }

    /**
     * 根据id查询变更详情
     *
     * @param id 变更类型id
     * @return
     */
    @RequestMapping("/getModifyDetailList")
    @LogRecord(description = "根据id查询变更详情", operationUnit = LogOperationUnit.BASE_ORGANIZATION, operationType = LogOperationType.SELECT)
    public PageInfo<BaseModifyDetail> getModifyDetailList(Page page, String id) {
        return organizationService.getModifyDetailList(page, id);
    }

    /**
     * 修改业务状态  1备案/0撤销
     *
     * @param id 企业id
     * @return 企业基本信息
     */
    @RequestMapping("/updateState")
    @LogRecord(description = "修改业务状态备案/撤销", operationUnit = LogOperationUnit.BASE_ORGANIZATION, operationType = LogOperationType.SELECT)
    public CommonResult updateState(@RequestParam("id") String id, @RequestParam("state") String state) {
        return organizationService.updateState(id, state);
    }

    /**
     * 开发企业
     *
     * @return
     */
    @RequestMapping("/selectOpenCommittee")
    @LogRecord(description = "开发企业", operationUnit = LogOperationUnit.BASE_ORGANIZATION, operationType = LogOperationType.SELECT)
    public List<BaseOrganization> selectOpenCommittee(String id) {
        return organizationService.selectOpenCommittee(id);
    }

    /**
     * 物业企业
     *
     * @return
     */
    @RequestMapping("/selectProperty")
    @LogRecord(description = "物业企业", operationUnit = LogOperationUnit.BASE_ORGANIZATION, operationType = LogOperationType.SELECT)
    public List<BaseOrganization> selectProperty(String id) {
        return organizationService.selectProperty(id);
    }


    /**
     * 查询开发企业，物业企业，施工企业，监理企业，审计企业下拉列表
     *
     * @param id   小区ID
     * @param type 类型 （01开发企业，02物业企业，03施工企业，04监理企业，08审计企业）
     * @return 企业下拉列表
     */
    @RequestMapping("/getOrgList")
    @LogRecord(description = "查询开发企业，物业企业，施工企业，监理企业，审计企业下拉列表", operationUnit = LogOperationUnit.BASE_ORGANIZATION, operationType = LogOperationType.SELECT)
    public List<BaseOrganization> getOrgList(String id, String type) {
        return organizationService.getOrgList(id, type);
    }

    /**
     * 施工企业
     *
     * @return
     */
    @RequestMapping("/getConstructionOrgList")
    public List<BaseOrganization> getSGOrgInfo() {
        return organizationService.getSGOrgInfo();
    }

    ;

    /**
     * 审计企业
     *
     * @return
     */
    @RequestMapping("/getAuditOrgList")
    public List<BaseOrganization> getSJOrgInfo() {
        return organizationService.getSJOrgInfo();
    }

    /**
     * 监理企业
     *
     * @return
     */
    @RequestMapping("/getSupervisionOrgList")
    public List<BaseOrganization> getJLOrgInfo() {
        return organizationService.getJLOrgInfo();
    }

    /**
     * 查询小区下的申请单位信息
     *
     * @param id 小区id
     * @return
     */
    @RequestMapping("/getApplyOrgList")
    public List<BaseOrganization> getSQOrgInfo(String id) {
        return organizationService.getSQOrgInfo(id);
    }

    @RequestMapping("/selectName")
    public CommonResult selectName(String name) {
        return organizationService.selectName(name);
    }

    @RequestMapping("/selectCountByDev")
    public PageInfo<BaseRegionInfo> selectCountByDev(Page page, BaseRegionInfo baseRegionInfo) {
        return organizationService.selectCountByDev(page, baseRegionInfo);
    }

    /**
     * 外网通过统一信用代码找回密码
     */
    @RequestMapping("/selectByPassWord")
    public CommonResult selectByPassWord(BaseOrganization baseOrganization) {
        return organizationService.selectByPassWord(baseOrganization);
    }

    /**
     * 重置密码
     */
    @RequestMapping("/resetPassword")
    public CommonResult resetPassword(BaseOrganization baseOrganization) {
        return organizationService.resetPassword(baseOrganization);
    }

    /**
     * 查询审核驳回
     */
    @RequestMapping("/rejectionExaminationApproval")
    public BaseOrganization rejectionExaminationApproval(String operNo, String arcType) {
        return organizationService.rejectionExaminationApproval(operNo, arcType);
    }

    /**
     * 获取外网物业企业确认变更接口
     *
     * @param modifyVO 变更项集合
     * @return 变更结果
     */
    @RequestMapping("/getExtraNetModify")
    public CommonResult getExtraNetModify(@RequestBody ModifyVO modifyVO) {
        return organizationService.getExtraNetModify(modifyVO);
    }

    /**
     * 查询监理企业信息
     * (用于外网调用，只查询监理人和监理电话)
     *
     * @param id 监理企业ID
     * @return 监理企业信息
     */
    @RequestMapping("/getOrgSupervisionInfo")
    public BaseOrganization getOrgSupervisionInfo(String id) {
        return organizationService.getOrgSupervisionInfo(id);
    }

    /**
     * 获取外网提醒列表
     *
     * @param page   分页实体
     * @param operNo 登录账号
     * @return 提醒列表
     */
    @RequestMapping("/getReminder")
    public  PageInfo<MessageVO> getReminder(Page page, String operNo) {
        return organizationService.getReminder(page, operNo);
    }
}
